package script.db

databaseChangeLog(logicalFilePath: 'script/db/hpfm_cusz_demo_order_line.groovy') {
    changeSet(author: "hzero@hand-china.com", id: "2022-07-12-hpfm_cusz_demo_order_line") {
        def weight = 1
        if (helper.isSqlServer()) {
            weight = 2
        } else if (helper.isOracle()) {
            weight = 3
        }
        if (helper.dbType().isSupportSequence()) {
            createSequence(sequenceName: 'hpfm_cusz_demo_order_line_s', startValue: "1")
        }
        createTable(tableName: "hpfm_cusz_demo_order_line", remarks: "") {
            column(name: "order_line_id", type: "bigint", autoIncrement: true, remarks: "订单行ID,主键") { constraints(primaryKey: true) }
            column(name: "order_id", type: "bigint", remarks: "订单头ID") { constraints(nullable: "false") }
            column(name: "goods", type: "varchar(" + 60 * weight + ")", remarks: "商品") { constraints(nullable: "false") }
            column(name: "unit_price", type: "decimal(20,2)", remarks: "单价") { constraints(nullable: "false") }
            column(name: "quantity", type: "int", remarks: "数量") { constraints(nullable: "false") }
            column(name: "remark", type: "longtext", remarks: "备注")
            column(name: "tenant_id", type: "bigint", remarks: "租户ID，hpfm_tenant.tenant_id") { constraints(nullable: "false") }
            column(name: "object_version_number", type: "bigint", defaultValue: "1", remarks: "行版本号，用来处理锁") { constraints(nullable: "false") }
            column(name: "creation_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "") { constraints(nullable: "false") }
            column(name: "created_by", type: "bigint", defaultValue: "-1", remarks: "") { constraints(nullable: "false") }
            column(name: "last_updated_by", type: "bigint", defaultValue: "-1", remarks: "") { constraints(nullable: "false") }
            column(name: "last_update_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "") { constraints(nullable: "false") }
            column(name: "attribute1", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute2", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute3", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute4", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute5", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute6", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute7", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute8", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute9", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute10", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute11", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute12", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute13", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute14", type: "varchar(" + 150 * weight + ")", remarks: "")
            column(name: "attribute15", type: "varchar(" + 150 * weight + ")", remarks: "")
        }


        addUniqueConstraint(columnNames: "order_id,goods", tableName: "hpfm_cusz_demo_order_line", constraintName: "hpfm_cusz_demo_order_line_u1")
    }
}